package main.java.indi.zyj.sword;

public class FindTargetIn2DPlants {

    public boolean findTargetIn2DPlants(int[][] plants, int target) {

        if (plants.length == 0 || plants[0].length == 0) {
            return false;
        }

        int row = plants.length, col = plants[0].length;

        int i = 0, j = col - 1;

        while (i < row && j >= 0) {
            if (plants[i][j] == target) {
                return true;
            } else if (plants[i][j] < target) {
                j--;
            } else {
                i++;
            }
        }

        return false;

    }

}
